﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TONLI.TJOA.Domain;
using TONLI.TJOA.Common;
using System.Collections.Generic;
using TONLI.Domain.RightManager;

namespace TONLI.TJOA
{
    public partial class pttcm : System.Web.UI.Page
    {
        protected Smmuser loginUser = null;

        public Smmuser LoginUser
        {
            get { return loginUser; }
            //set { loginUser = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                this.Response.Redirect("~/login.aspx");
            }

            loginUser = Session["user"] as Smmuser;
            if (loginUser == null)
            {
                this.Response.Redirect("~/login.aspx");
            }
            if (!IsPostBack)
            {
           //     for(int i=0;i>-6;i--)
           //DropDownList3.Items.Add(DateTime.Now.AddYears(i).Year.ToString());
                DropDownList3.Text = System.DateTime.Today.Year.ToString();
                string txt = System.DateTime.Today.Month.ToString();
                if (txt.Length == 1) { txt = "0" + txt; }
                DropDownList4.Text = txt;
                //Session["date"] = DropDownList3.Text + DropDownList4.Text;
                Hashtable ha = new Hashtable();
                
                Smmuser sm = Session["user"] as Smmuser;

                VsmdgroupProg sum = GetRightprog(sm.Userid, "aq010922");
              

                if (Convert.ToInt32(sum.upd) <1)
                {
                    ASPxGridView1.Columns[10].Visible = false;
                }

              
            else
            {
            }
                //ha.Add("Date",  DropDownList3.Text + DropDownList4.Text);
               
                //Session["S1"] = ha;
                //ObjectDataSource1.Select();
                Initdata(DropDownList3.Text + "-"+DropDownList4.Text+"-01");

            }
        }
        public void Initdata(string s)
        { 
            string[] str=new string[13];
            string strdate="";
            int icount = 0;
            str[0] = "车间正副职";
            str[1] = "监控人员";
            str[2] = "科室人员";
            str[3] = "车间信息处罚";
            str[4] = "监控信息处罚";
            str[5] = "科室信息处罚";
            str[6] = "段通报信息处罚";
            str[7] = "工务信息处罚";
            str[8] = "工务通报信息处罚";
            str[9] = "路局信息处罚";
            str[10] = "路局通报信息处罚";
            str[11] = "车间信息评比";
            str[12] = "信息考核领导组";
            foreach(string stemp in str)
            {
                strdate = "Xm='" + stemp + "' and Sj='"+s+"'";
                //strdate = "Xm=" + stemp;
                int li = (int)(DataService.BaseService().GetObject("SelectAQK_PEAXByCount", strdate));
                if (li == 0)
                {
                    AQK_PEAX ap=new AQK_PEAX();
                    ap.Uid = Guid.NewGuid().ToString();
                    ap.Xm=stemp;
                    ap.Sj=DateTime.Parse(s);
                    ap.Cj=DateTime.Now;
                    DataService.BaseService().Create<AQK_PEAX>(ap);
                }



            }
            Hashtable ha = new Hashtable();

            ha.Add("Date", s);
            Session["S1"] = ha;
            this.ObjectDataSource1.Select();
        }

        protected void ASPxButton1_Click(object sender, EventArgs e)
        {
            Initdata(DropDownList3.Text + "-" + DropDownList4.Text + "-01");
        }

        protected void ASPxGridView1_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
        {
            if (ASPxGridView1.IsEditing)
            {
            //    if (e.Column.FieldName == "Sh")
            //    {
                
            //    }
            }

        }

        protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {

            AQK_PEAX EC = new AQK_PEAX();
            //EC.Xm = e.NewValues["Xm"].ToString();
            EC.Bz = (e.NewValues["Bz"] == null) ? "" : e.NewValues["Bz"].ToString();
            if (e.NewValues["Sl"] == null) EC.Sl = 0;
            else
                EC.Sl = Convert.ToInt16(e.NewValues["Sl"].ToString());
            if (e.NewValues["Fk"] == null) EC.Fk = 0;
            else
                EC.Fk = Convert.ToDouble(e.NewValues["Fk"].ToString());
            if (e.NewValues["Jl"] == null) EC.Jl = 0;
            else
                EC.Jl = Convert.ToDouble(e.NewValues["Jl"]);
            EC.Uid = e.Keys["Uid"].ToString();
           
            Session["Update"] = EC;

            ObjectDataSource1.Update();
            e.Cancel = true;
            ASPxGridView1.CancelEdit();   
        }

        protected void ASPxButton2_Click(object sender, EventArgs e)
        {
            ASPxGridViewExporter1.WriteXlsToResponse(Server.UrlEncode(ASPxGridView1.SettingsText.Title));
        }
  private VsmdgroupProg GetRightprog(string userID, string progID)
        {

            IList<VsmdgroupProg> smu = TONLI.TJOA.Common.DataService.BaseService().GetList<VsmdgroupProg>("SelectSmdgroupListByUserID", userID);
            if (smu.Count == 0)
                return null;
            VsmdgroupProg vv = new VsmdgroupProg();
            foreach (VsmdgroupProg vs in smu)
            {
                if (vs.Progid == progID)
                    vv = vs;
            }

            return vv;
        }
    }
}
